package com.recharge.web.controller;


import com.recharge.common.annotation.OperationLogDetail;
import com.recharge.common.domain.PageDO;
import com.recharge.common.enums.OperationLogType;
import com.recharge.common.result.ResultDO;
import com.recharge.common.result.web.ObjectResponse;
import com.recharge.domain.query.ProviderGoodsQueryDO;
import com.recharge.domain.vo.ProviderGoodsDO;
import com.recharge.service.ProviderGoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 商品供货单
 * </p>
 *
 * @author wangli
 * @since 2020-10-20
 */
@RestController
@RequestMapping("/provider-goods")
@Api
public class ProviderGoodsController extends BaseController {
    @Autowired
    private ProviderGoodsService providerGoodsService;

    //@RequiresPermissions("provider-goods:page")
    @OperationLogDetail(detail = "分页查询卡密供应单记录", operationType = OperationLogType.SELECT)
    @RequestMapping(value = "/page.html", method = RequestMethod.POST)
    @ApiOperation(value = "分页查询卡密供应单记录", notes = "")
    public ObjectResponse<PageDO> page(@RequestBody @ApiParam(name = "查询对象",value = "") ProviderGoodsQueryDO query) {
        ObjectResponse<PageDO> response = new ObjectResponse<>();
        ResultDO result = providerGoodsService.find(query);
        if (result.isSuccess()) {
            response.setData((PageDO) result.getModel(ResultDO.FIRST_MODEL_KEY));
        } else {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }

    @RequiresPermissions("provider-goods:update")
    @OperationLogDetail(detail = "修改卡密供应单", operationType = OperationLogType.UPDATE)
    @RequestMapping(value = "/update.html", method = RequestMethod.POST)
    @ApiOperation(value = "修改卡密供应单", notes = "")
    public ObjectResponse<Object> update(@RequestBody ProviderGoodsDO param) {
        ObjectResponse<Object> response = new ObjectResponse<>();
        param.setModifier(getUserName());
        ResultDO result = providerGoodsService.edit(param);
        if (result.isSuccess()) {
            response.setData(null);
        } else {
            response.setStatus(result.getErrorCode().getCode());
            response.setMsg(result.getErrorCode().getMsg());
        }
        return response;
    }

}

